package cn.ljw.dto;

import cn.ljw.utils.BlogUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * @author 一朝风月
 * @date 2024/3/27 18:44
 * @Code 面向注解面向卿，终无解释再无你
 * @description 分页 任意携带
 */
@AllArgsConstructor
@Data
public class Pagination <T>{
    private long pageNum;
    private long pageSize;
    private long total;
    private long pages;
    private String orderBy;
    private List<T> list;
    public static <S> Pagination<S> of(IPage<S> page) {
        return new Pagination<>(
                page.getCurrent(),
                page.getSize(),
                page.getTotal(),
                page.getPages(),
                BlogUtils.objectToJson(page.orders()),
                page.getRecords()
        );
    }
}
